package math;

public class GasStation134 {

    public int canCompleteCircuit(int[] gas, int[] cost) {
        for (int i = 0; i < gas.length; i++) {
            int gass = 0;
            int costt = 0;
            for (int j = i; j < i + gas.length; j++) {
                gass += gas[j%gas.length];
                costt += cost[j%gas.length];
                if (costt > gass) {
                    i = j;
                    break;
                }
                if(j==i+gas.length-1){
                    return i;
                }
            }
        }
        return -1;
    }
}
